package com.central.scheduler.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.central.common.service.impl.SuperServiceImpl;
import com.central.scheduler.api.service.IProcessDefinitionService;
import com.central.scheduler.api.service.IProcessLineageService;
import com.central.scheduler.dao.mapper.ProcessDefinitionMapper;
import com.central.scheduler.dao.mapper.ProcessLineageMapper;
import com.central.scheduler.dao.model.ProcessDefinition;
import com.central.scheduler.dao.model.ProcessLineage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author Tindy
 * @date 2021/12/15
 * @describe
 */
@Service
public class ProcessLineageServiceImpl extends SuperServiceImpl<ProcessLineageMapper,ProcessLineage> implements IProcessLineageService {

    @Autowired
    private ProcessDefinitionMapper processDefinitionMapper;
    @Override
    public Map<String, Object> list(Long proId, String processName) {
        HashMap<String, Object> result = new HashMap<>();
        Set<Long> processCodes = processDefinitionMapper.getCodes(proId,processName);
        if(processCodes.isEmpty()) return result;
        List<ProcessLineage> lineages= baseMapper.getLineages(processCodes);
        for (ProcessLineage lineage : lineages) {
            processCodes.add(lineage.getSrcProcessCode());
            processCodes.add(lineage.getDestProcessCode());
        }
        List<ProcessDefinition> processDefinitions=processDefinitionMapper.queryByCodes(processCodes);
        result.put("nodes",processDefinitions);
        result.put("lineages",lineages);
        return result;
    }
}
